from apps.blog.models import Category, Entry
from django.template import Library, Node

register = Library()

def build_category_list(parser, token):
    """
    {% get_category_list %}
    """
    return CategoryMenuObject()

class CategoryMenuObject(Node):
    def render(self, context):
        output = ['']

        for blogcategory in Category.objects.all():
            number = blogcategory.entry_set.count()
            if number >= 1:
                output.append(blogcategory)

        context['blog_categories'] = output
        return ''

register.tag('get_category_list', build_category_list)